package com.wut.clock.controller;

import com.wut.clock.common.api.CommonPage;
import com.wut.clock.common.api.CommonResult;
import com.wut.clock.entity.SysLoginLog;
import com.wut.clock.entity.SysOperLog;
import com.wut.clock.service.ILogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZYH
 * @unit D9Lab
 * @description 日志管理
 * @date 2022/5/30 18:22
 */
@Slf4j
@Api(value="日志管理器",tags = {"日志管理器"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys/log")
public class LogController {

    private final ILogService logService;

    @ApiOperation("根据条件查询操作日志")
    @GetMapping("/getOperLogByCondition")
    public CommonResult<CommonPage<SysOperLog>> getOperLogByCondition(@RequestParam(required = false) String title,
                                                                      @RequestParam(required = false) String operName,
                                                                      @RequestParam(required = false) Integer status,
                                                                      @RequestParam(required = false) String deptName,
                                                                      @RequestParam(required = false) Integer companyId,
                                                                      @RequestParam(required = false) String startTime,
                                                                      @RequestParam(required = false) String endTime,
                                                                      @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                                                      @RequestParam(value="size",defaultValue ="5") Integer pageSize){
        List<SysOperLog> operLogList = logService.getOperLogByCondition(title,operName,status,deptName,companyId,startTime,endTime,pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(operLogList),"根据条件查询操作日志成功");
    }


    @ApiOperation("根据条件查询登录日志")
    @GetMapping("/getLoginLogByCondition")
    public CommonResult<CommonPage<SysLoginLog>> getLoginLogByCondition(@RequestParam(required = false) String userName, @RequestParam(required = false) String ipaddr,
                                                                        @RequestParam(required = false) Integer status,
                                                                        @RequestParam(required = false) String startTime,
                                                                        @RequestParam(required = false) String endTime,
                                                                        @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                                                        @RequestParam(value="pageSize",defaultValue ="5") Integer pageSize){
        List<SysLoginLog> loginLogList = logService.getLoginLogByCondition(userName, ipaddr, status, startTime, endTime, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(loginLogList),"根据条件查询登录日志成功");
    }

}
